import { PIC_URL } from './../../providers/Config';
import { Events } from 'ionic-angular';
import { BasePage } from './../../pages/basePage';
import { UserService } from './../../providers/UserService';
import { Component, Injector } from '@angular/core';
import { StorageService } from './../../providers/StorageService';
declare var $: any;

/**
 * Generated class for the ShopEvaluateComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'shop-evaluate',
  templateUrl: 'shop-evaluate.html'
})
export class ShopEvaluateComponent extends BasePage {
  picrooturl = '';
  userinfo={}
  shopList: any[] = [];

  five = [1, 2, 3, 4, 5];
  remark_time:any;  //评价时间
  evaluateIndex: number;
  evaluate = ['继续努力', '差一点', '很好', '非常好', '非常好'];
  error_msg = '暂无评价信息！'
  commentsData=[]
  pop = 1;    //分页
  bottom1: boolean = false;    //加载全部底部显示器
  flag: boolean;    //缺省字
  
  constructor(public injector: Injector, public userService: UserService, public stc:StorageService, public events: Events) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
    console.log(this.shopList)
    this.checkShopCommentsAPI('');
  }
  // /** 获取评论 */
  async checkShopCommentsAPI(infiniteScroll) {
    let param={shop_id:this.userinfo['shop_id'],pop:this.pop};
    console.log(param);
    let res = await this.userService.checkShopCommentsAPI(param);
    console.log(res);
    if (res.code == 1) {
      this.pop++;
      this.shopList = this.shopList.concat(res.data);
      if(this.shopList.length == 0){
        this.flag=false;
      }else{
        this.flag=true;
      }
      if(infiniteScroll){
        infiniteScroll.complete(); //请求完成数据更新页面
        if(res.data.length<6){
            $(".box5 ion-infinite-scroll-content").css("display","none");
            this.bottom1=true;
        }
      }
    } else {
      let toast = this.toastCtrl.create({
        message: res.msg,
        duration: 1500,
        position: 'bottom',
      })
      toast.present();
    }
  }
  isArray(obj) {
    // console.log(Array.isArray(obj));
    // if (Array.isArray(obj)) {
    //   console.log(obj.length)
    // }
    return Array.isArray(obj)
  }
  /**
   * 跳转到评论详情
   * @param list  该条评论信息
   */
  toDetail(list){
    this.stc.removeItem("back2");
    let modal= this.modalCtrl.create("CommentDetailPage",{list:list['remark_id'],par:3});
    modal.onDidDismiss(data => {
      if(data == "ok"){
        console.log("评论完毕")
        this.again();
      }
    });
    modal.present();
  }
  //无限滚动
  doInfinite(infiniteScroll) {
    this.bottom1 = false;
    this.checkShopCommentsAPI(infiniteScroll);
  }
  again(){
    this.pop=1;
    this.bottom1=false;
    this.shopList=[];
    $(".box5 ion-infinite-scroll-content").css("display","block");
    this.checkShopCommentsAPI('')
  }
}
